package com.zdsoft.blp.zongbuju.shouye.wuye.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.imageTrans.CircleImage;
import com.zdsoft.blp.zongbuju.shouye.wuye.entity.WuYe;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/8/30.
 */
public class WYAdapter extends BaseAdapter{
    private List<WuYe> list;
    private Context context;
    private LayoutInflater inflater;

    public WYAdapter(Context context, List<WuYe> list) {
        this.context = context;
        this.list = list;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.wy_item,null);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.iv);
            holder.tv_title= (TextView) convertView.findViewById(R.id.tv_title);
            holder.tv_content= (TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        WuYe wuye=list.get(position);

        holder.tv_title.setText(wuye.getTitle());
        holder.tv_content.setText(wuye.getContent());
        Picasso.with(context).load(wuye.getImgPath()).error(R.drawable.no_pic).placeholder(R.drawable.loading).transform(new CircleImage()).into(holder.iv);
        return convertView;
    }

    class ViewHolder{ //先创建一个内部类 ViewHolder  内部定义item布局中的控件
        ImageView iv;
        TextView tv_title;
        TextView tv_content;
    }

    public void setList(List<WuYe> list) {
        this.list = list;
    }
}
